#include "musiclist.h"

MusicList::MusicList()
{    
}

void MusicList::addMusicByUrl(const QList<QUrl> &musicUrls)
{
    for(auto url:musicUrls)
    {
        //由于添加进来的文件不一定是歌曲文件，因此需要再次筛选出音乐文件
        QMimeDatabase db;
        QMimeType mime = db.mimeTypeForFile(url.toLocalFile());
        //取到到了文件的mime类型
        if(mime.name()=="audio/mpeg"||mime.name()=="audio/flac"||mime.name() == "audio/wav")
        {
            Music music(url);
            musicList.push_back(music);
        }

    }
}

iterator MusicList::findMusicByMusicId(const QString &musicId)
{
    for(auto it = musicList.begin();it!=musicList.end();++it)
    {
        if(it->getMusicId() == musicId)
            return it;
    }
    return end();
}

iterator MusicList::begin()
{
    return musicList.begin();
}

iterator MusicList::end()
{
    return musicList.end();
}










